import {
    WFDynaEditViewActionType,
    IWFDynaEditViewAbility,
    IWFDynaEditViewControllerParams,
    IWFDynaEditViewModel,
    IWFDynaEditViewStore,
    IParam,
    IViewEvent,
    IWFDynaEditViewController,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
    getViewClassNames,
    useViewAction,
    useViewBasic,
    useViewControllerParams,
    useViewProps,
} from '../use-view';

/**
 * 获取动态工作流编辑视图输入参数
 *
 * @export
 * @return {*}
 */
export function useWFDynaEditViewProps() {
    return {
        ...useViewProps()
    };
}

/**
 * 获取动态工作流编辑视图基础
 *
 * @export
 * @param {IWFDynaEditViewModel} model 动态工作流编辑视图模型
 * @param {IParam} props 输入参数
 * @return {*}
 */
export function useWFDynaEditViewBasic(model: IWFDynaEditViewModel, props: IParam) {
    const getClassNames = (props: IParam) => {
        return getViewClassNames(model, props);;
    }
    return {
        ...useViewBasic(model, props),
        getClassNames,
    };
}

/**
 * 动态工作流编辑视图行为
 *
 * @export
 */
export function useWFDynaEditViewAction(controller: any) {
    const handleActionClick = (event: MouseEvent, item: IParam) => {
        controller.handleActionClick(event, item);
    }
    const handleDynamicToolbarClick = (item: IParam) => {
        controller.handleDynamicToolbarClick(item);
    }
    const handleToolbarItemClick = (controller: IWFDynaEditViewController<IWFDynaEditViewStore, IWFDynaEditViewAbility>, name: string, event: MouseEvent, logic: any) => {
        controller.handleToolbarItemClick(event, logic);
    }
    return {
        ...useViewAction(controller),
        handleActionClick,
        handleDynamicToolbarClick,
        handleToolbarItemClick
    };
}

/**
 * 获取动态工作流编辑视图控制器输入参数
 *
 * @export
 * @param {IWFDynaEditViewModel} model
 * @param {IParam} props
 * @param {QXEvent<IViewEvent<WFDynaEditViewActionType, IWFDynaEditViewAbility>>} evt
 * @return {*}  {IWFDynaEditViewControllerParams<WFDynaEditViewActionType, IWFDynaEditViewAbility>}
 */
export function useWFDynaEditViewControllerParams(
    model: IWFDynaEditViewModel,
    props: IParam,
    evt: QXEvent<IViewEvent<WFDynaEditViewActionType, IWFDynaEditViewAbility>>
): IWFDynaEditViewControllerParams<WFDynaEditViewActionType, IWFDynaEditViewAbility> {
    return {
        ...useViewControllerParams<IWFDynaEditViewStore, IWFDynaEditViewModel>(
            model,
            props,
            evt
        ),
    };
}
